import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/ext.dart';

/// 通用 自定义Checkbox
/// demo:
/// CustomMultiChoiceCheckbox(
///         choicesText: [choice1Text, choice2Text, choice3Text],
///         initialChoices: [initialChoice1, initialChoice2, initialChoice3],
///         onChoiceChanged: (index, value) {
///           AppToast.showSuccess('选项 $index 被选中$value');
///         },
///         checkboxBuilder: (isSelected, onChanged) {
///           return CustomCheckbox(
///             isChecked: isSelected,
///             onChanged: (bool? newValue) => onChanged(),
///           );
///         },
///       )
class CustomCheckbox extends StatelessWidget {
  const CustomCheckbox({required this.isChecked, required this.onChanged, this.enabled = true, super.key});

  final bool isChecked;

  ///设置不可编辑;
  final bool enabled;
  final ValueChanged<bool> onChanged;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: isChecked ? Colors.blue : Colors.white,
        border: Border.all(
          color: isChecked ? Colors.blue : Colors.grey, // 选中和未选中的边框颜色
          width: 1.0,
        ),
        borderRadius: BorderRadius.circular(20),
      ),
      width: 20,
      height: 20,
      child: isChecked ? const Icon(Icons.check, size: 16, color: Colors.white) : null,
    ).clickOnce(() {
      enabled ? onChanged(!isChecked) : null;
    });
  }
// @override
// Widget build(BuildContext context) {
//   return Checkbox(
//     value: isChecked,
//     materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
//     onChanged: (bool? newValue) => onChanged(!isChecked),
//     // activeColor: Colors.red,
//     // //勾选后的框颜色为蓝色
//     // checkColor: Colors.blue,
//     //勾的颜色为蓝色
//     shape: RoundedRectangleBorder(
//       // 圆角正方形形状
//       borderRadius: BorderRadius.circular(4),
//     ),
//   );
// }
}
